import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_reader/config/storage_manager.dart';
import 'package:flutter_reader/res/colors.dart';
import 'package:flutter_reader/ui/home/home_page.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized(); // 解决 async main 报错
  await StorageManager.init();
  runApp(MyApp());

  if (Platform.isAndroid) {
    SystemUiOverlayStyle style =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(style);
  }
}

// 全局的路由监听者，可在需要的widget中添加，应该放到一个全局定义的文件中
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Reader',
      navigatorObservers: [routeObserver],
      theme: ThemeData(
        primaryColor: Colors.white,
        dividerColor: Color(0xffeeeeee),
        scaffoldBackgroundColor: MyColors.paper,
        textTheme: TextTheme(bodyText1: TextStyle(color: MyColors.darkGray)),
      ),
      home: HomePage(),
    );
  }
}
